<!DOCTYPE html>
<html lang="en" xml:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
</head>
<body>

<div class="layui-container" style="width:400px;">
    <form action="" class="layui-form" id="passForm">
        <div class="layui-form-item">
            <label class="layui-form-label">旧密码</label>
            <div class="layui-input-block">
                <input type="password" name="oldPassword" class="layui-input" lay-verify="required"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" id="password" class="layui-input" layverify="required"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
                <input type="password" name="rePassword" lay-verify="required|repass" class="layui-input"
                       verify="required"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="baseSubmit">保存
                </button>
            </div>
        </div>
    </form>
</div>

</body>
<script src="/layui/layui.js"></script>
<script src="/js/core.util.js"></script>
<script>
    layui.use(['form', 'layer', 'jquery'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;

        // 校验两个新密码是否一致
        form.verify({
            rePassword: function (value) {
                const pass = $("#password").val();
                if (pass !== value) {
                    return '两次输入的密码不一致';
                }
            }
        });

        // 提交
        form.on('submit(baseSubmit)', function (data) {
            CoreUtil.sendAjax("/exam/user/password", JSON.stringify(data.field), function (res) {
                layer.msg("密码已经变更请重新登录");
                top.window.location.href = "/index/login";
            }, "PUT", true);
            return false;
        })


    });
</script>
</html>